<?PHP
	require_once($_SERVER['DOCUMENT_ROOT']."/config/env.php");
	require_once(PATH.".\\model\\SQL.php");
	require_once(PATH.".\\model\\User.php");
	require_once(PATH.".\\functions\\controller_functions.php");
	
	session_start();
	
	abstract class AbstractController
	{
		private $loading_time;
		
		public function __construct()
		{
			$this->loading_time = -microtime_float();;
		}
		
		abstract public function processPage();
		public function createOutput($data_array)
		{
			ob_start();
			include(PATH."templates/demoty/index.php");

			$output = ob_get_contents();
			$output = preg_replace("/\{\{([A-Za-z0-9_\-]+)\}\}/e", "replaceTag('$1',\$data_array )", $output);
			$output = evalConditionTags($output , $data_array);

			ob_end_clean();
			$this->loading_time += microtime_float();

			$data_array["footer_loading_time"] = $this->loading_time;
			$output = preg_replace("/\{\{([A-Za-z0-9_\-]+)\}\}/e", "replaceTag('$1',\$data_array )", $output);

			return $output;
		}

		public function getLoggedUser()
		{
			if($_SESSSION["logged"] === true)
			{
				$user = new User();
				$user->login =$_SESSSION["username"];
				$user->load();
				if($user->hashed_password != $_SESSION["password"])
				{
					return NULL;
				}
				return $user;
			}
			return NULL;
		}
	}
?>